// 加载菜单对应的页面
const FetchHtml = require('./fetch-html');

module.exports = function( id, pageName ){

  return new Promise( resolve=>{

    $('#'+id).html('');

    FetchHtml({
      url:'./role.html',
    });

    FetchHtml({url: `./${pageName}.html`}).then( data=>{

      data = data.replace('<template>', '').replace('</template>', '');
      let oDiv = document.createElement('div');
      oDiv.innerHTML = data;
      document.getElementById(id).appendChild(oDiv);

      let oScript = document.createElement('script');
      oScript.src = `/admin_${pageName}.bundle.js`;
      oDiv.appendChild(oScript);

      resolve(true);

    } );

  } );

};
